package com.esm.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.esm.dao.DepartmentDao;
import com.esm.model.Department;
import com.esm.model.User;
import com.esm.utils.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * DepartmentDaoImpl
 * 部门Dao层实现类
 * @author 魏长均
 *
 */
public class DepartmentDaoImpl implements DepartmentDao 
{

	public JSONArray findDeptName() 
	{
		JSONArray jao = new JSONArray();
		//数据库操作SQL数据
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT * FROM ems_dept");
		//定义数据库连接对象
		Connection con = null;
		//定义预编译对象
		PreparedStatement pst = null;
		try 
		{
			//连接数据库
			con = JDBCUtil.getConnection();
			//生成预编译对象
			pst = con.prepareStatement(sql.toString());
			//数据库执行查询语句
			ResultSet rs = pst.executeQuery();
			while(rs.next())
			{
				JSONObject jo = new JSONObject();
				jo.put("dep_id", rs.getInt("dep_id"));
				jo.put("dep_name", rs.getString("dep_name"));
				jao.add(jo);
			}
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
		JDBCUtil.closeJDBC(pst, con);
		return jao;
	}

}
